<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>知识总结（七）HTML和CSS基础 | lty的博客</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/blog/favicon.ico">
    <meta name="description" content="山重水复疑无路，柳暗花明又一村">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/blog/assets/css/0.styles.ca934e57.css" as="style"><link rel="preload" href="/blog/assets/js/app.2c497286.js" as="script"><link rel="preload" href="/blog/assets/js/3.1e41fb2d.js" as="script"><link rel="preload" href="/blog/assets/js/1.a1bf8e1e.js" as="script"><link rel="preload" href="/blog/assets/js/37.38b67684.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.595db545.js"><link rel="prefetch" href="/blog/assets/js/11.a57c5d33.js"><link rel="prefetch" href="/blog/assets/js/12.bbd60eab.js"><link rel="prefetch" href="/blog/assets/js/13.0a322639.js"><link rel="prefetch" href="/blog/assets/js/14.45182424.js"><link rel="prefetch" href="/blog/assets/js/15.8bfecd82.js"><link rel="prefetch" href="/blog/assets/js/16.f295f32f.js"><link rel="prefetch" href="/blog/assets/js/17.de5dabe7.js"><link rel="prefetch" href="/blog/assets/js/18.dbcf4366.js"><link rel="prefetch" href="/blog/assets/js/19.dc4ed650.js"><link rel="prefetch" href="/blog/assets/js/20.9000ffe3.js"><link rel="prefetch" href="/blog/assets/js/21.50c08d3d.js"><link rel="prefetch" href="/blog/assets/js/22.849f004a.js"><link rel="prefetch" href="/blog/assets/js/23.4c25a240.js"><link rel="prefetch" href="/blog/assets/js/24.a2930e6d.js"><link rel="prefetch" href="/blog/assets/js/25.20efd6e6.js"><link rel="prefetch" href="/blog/assets/js/26.1881faa9.js"><link rel="prefetch" href="/blog/assets/js/27.18bc2dfe.js"><link rel="prefetch" href="/blog/assets/js/28.903117fb.js"><link rel="prefetch" href="/blog/assets/js/29.e1d01502.js"><link rel="prefetch" href="/blog/assets/js/30.27049c11.js"><link rel="prefetch" href="/blog/assets/js/31.455cb7a6.js"><link rel="prefetch" href="/blog/assets/js/32.72aa7ec8.js"><link rel="prefetch" href="/blog/assets/js/33.6362e43e.js"><link rel="prefetch" href="/blog/assets/js/34.30160844.js"><link rel="prefetch" href="/blog/assets/js/35.991fefa1.js"><link rel="prefetch" href="/blog/assets/js/36.3350110b.js"><link rel="prefetch" href="/blog/assets/js/38.33876f62.js"><link rel="prefetch" href="/blog/assets/js/4.870f2524.js"><link rel="prefetch" href="/blog/assets/js/5.516ed845.js"><link rel="prefetch" href="/blog/assets/js/6.710883e3.js"><link rel="prefetch" href="/blog/assets/js/7.3579268a.js"><link rel="prefetch" href="/blog/assets/js/8.1e580575.js"><link rel="prefetch" href="/blog/assets/js/9.08e245bf.js">
    <link rel="stylesheet" href="/blog/assets/css/0.styles.ca934e57.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1aefc0b4><div data-v-1aefc0b4><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1aefc0b4 data-v-1aefc0b4><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>lty的博客</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2>山重水复疑无路，柳暗花明又一村</p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>lty</span>
            
          <!---->
          2022
        </a></span></div></div> <div class="hide" data-v-1aefc0b4><header class="navbar" data-v-1aefc0b4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/logo.png" alt="lty的博客" class="logo"> <span class="site-name">lty的博客</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/JavaScript/" class="nav-link"><i class="undefined"></i>
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/投资/" class="nav-link"><i class="undefined"></i>
  投资
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/计算机网络/" class="nav-link"><i class="undefined"></i>
  计算机网络
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/前端相关/" class="nav-link"><i class="undefined"></i>
  前端相关
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/知识总结/" class="nav-link"><i class="undefined"></i>
  知识总结
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      关于
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/ekzodia_lty" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1aefc0b4></div> <aside class="sidebar" data-v-1aefc0b4><div class="personal-info-wrapper" data-v-39576ba9 data-v-1aefc0b4><img src="/blog/avatar.jpg" alt="author-avatar" class="personal-img" data-v-39576ba9> <h3 class="name" data-v-39576ba9>
    lty
  </h3> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>27</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>18</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link"><i class="iconfont reco-home"></i>
  主页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/JavaScript/" class="nav-link"><i class="undefined"></i>
  JavaScript
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/投资/" class="nav-link"><i class="undefined"></i>
  投资
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/计算机网络/" class="nav-link"><i class="undefined"></i>
  计算机网络
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/前端相关/" class="nav-link"><i class="undefined"></i>
  前端相关
</a></li><li class="dropdown-item"><!----> <a href="/blog/categories/知识总结/" class="nav-link"><i class="undefined"></i>
  知识总结
</a></li></ul></div></div><div class="nav-item"><a href="/blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/blog/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      关于
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/ekzodia_lty" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>知识总结（七）HTML和CSS基础</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>lty</span>
            
          <!---->
          2022
        </a></span></div></div> <div data-v-1aefc0b4><main class="page"><section><div class="page-title"><h1 class="title">知识总结（七）HTML和CSS基础</h1> <div data-v-f875f3fc><i class="iconfont reco-account" data-v-f875f3fc><span data-v-f875f3fc>lty</span></i> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>2/10/2022</span></i> <i class="iconfont reco-eye" data-v-f875f3fc><span id="/blog/blogs/Summary/7.htmlcss.html" data-flag-title="Your Article Title" class="leancloud-visitors" data-v-f875f3fc><a class="leancloud-visitors-count" style="font-size:.9rem;font-weight:normal;color:#999;"></a></span></i> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>HTML</span></i></div></div> <div class="theme-reco-content content__default"><h2 id="h5新增特性"><a href="#h5新增特性" class="header-anchor">#</a> H5新增特性</h2> <ol><li>语义化标签</li> <li>input新增的属性以及类型</li> <li>本地存储。（储存在单个页面里，不是整个浏览器）</li> <li>canvas画布，svg图像绘制</li> <li>地理定位</li> <li>离线web应用</li> <li>多媒体支持 (<code>&lt;video&gt;</code>和<code>&lt;audio&gt;</code>等)</li></ol> <h2 id="如何理解-html-语义化"><a href="#如何理解-html-语义化" class="header-anchor">#</a> 如何理解 HTML 语义化？</h2> <ul><li>让人更容易读懂（增加代码可读性）。</li> <li>让搜索引擎更容易读懂，有助于爬虫抓取更多的有效信息，爬虫依赖于标签来确定上下文和各个关键字的权重（SEO）。</li> <li>在没有 CSS 样式下，页面也能呈现出很好地内容结构、代码结构。</li></ul> <h2 id="块级元素与行内元素"><a href="#块级元素与行内元素" class="header-anchor">#</a> 块级元素与行内元素</h2> <p>常见的块级元素：</p> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>div</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h1</span><span class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>h6</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ol</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>ul</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>dl</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>常见的行内元素：</p> <div class="language-html line-numbers-mode"><pre class="language-html"><code><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>a</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>span</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>i</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>em</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>label</span><span class="token punctuation">&gt;</span></span>,<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span><span class="token punctuation">&gt;</span></span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><hr> <h2 id="css3新增特性"><a href="#css3新增特性" class="header-anchor">#</a> CSS3新增特性</h2> <ol><li>新增选择器：子选择器，兄弟选择器，伪类元素选择器，属性选择器。</li> <li>CSS3盒模型：可以用box-sizing来指定content-sizing和border-sizing。</li> <li>边框圆角 border-radius。</li> <li>文字阴影 text-shadow。</li> <li>border-image</li> <li>自动换行：word-wrap</li> <li>transform变换效果 （后面可以跟translate）</li> <li>animation动画效果</li> <li>transition过渡效果（后面可以跟all）</li></ol> <h2 id="margin负值问题"><a href="#margin负值问题" class="header-anchor">#</a> margin负值问题</h2> <ul><li>margin-top和margin-left负值，元素向上、向左移动；</li> <li>margin-right负值，右侧元素 左移，自身不受影响；</li> <li>margin-bottom负值，下方元素上移，自身不受影响；</li></ul> <h2 id="水平垂直居中方法"><a href="#水平垂直居中方法" class="header-anchor">#</a> 水平垂直居中方法</h2> <p><strong>水平居中</strong></p> <ul><li>inline元素：text-align:center;</li> <li>block元素：margin:auto;</li> <li>absolute元素：left:50%+margin-left负值;</li></ul> <p><strong>垂直居中</strong></p> <ul><li>inline元素：line-height的值等于height值;</li> <li>absolute元素：top:50%+margin-top负值;(必须知道子元素的宽高)</li> <li>absolute元素：transform(-50%,-50%);</li> <li>absolute元素：top,left,bottom,right=0;   margin:auto;</li></ul> <p><strong>水平垂直居中代码实现</strong></p> <p>绝对定位解决方案</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">//最早实现垂直居中的技术是需要一个固定的宽度和高度：
main</span> <span class="token punctuation">{</span> 
    <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
    <span class="token property">top</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span> 
    <span class="token property">left</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span> 
    <span class="token property">margin-top</span><span class="token punctuation">:</span> -3em<span class="token punctuation">;</span> <span class="token comment">/* 6/2 = 3 */</span> 
    <span class="token property">margin-left</span><span class="token punctuation">:</span> -9em<span class="token punctuation">;</span> <span class="token comment">/* 18/2 = 9 */</span> 
    <span class="token property">width</span><span class="token punctuation">:</span> 18em<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span> 6em<span class="token punctuation">;</span> 
<span class="token punctuation">}</span>

<span class="token selector">// 如果使用 calc( ) 可以减少两个样式,缺点是兼容性不太好。
main</span> <span class="token punctuation">{</span> 
    <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
    <span class="token property">top</span><span class="token punctuation">:</span> <span class="token function">calc</span><span class="token punctuation">(</span>50% - 3em<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token property">left</span><span class="token punctuation">:</span> <span class="token function">calc</span><span class="token punctuation">(</span>50% - 9em<span class="token punctuation">)</span><span class="token punctuation">;</span> 
    <span class="token property">width</span><span class="token punctuation">:</span> 18em<span class="token punctuation">;</span> <span class="token property">height</span><span class="token punctuation">:</span> 6em<span class="token punctuation">;</span> 
<span class="token punctuation">}</span>

<span class="token selector">//CSS3中的解决方案，使用 transform 中的 translate() 百分比   
main</span> <span class="token punctuation">{</span> 
    <span class="token property">position</span><span class="token punctuation">:</span> absolute<span class="token punctuation">;</span>
    <span class="token property">top</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span> <span class="token property">left</span><span class="token punctuation">:</span> 50%<span class="token punctuation">;</span> 
    <span class="token property">transform</span><span class="token punctuation">:</span> <span class="token function">translate</span><span class="token punctuation">(</span>-50%<span class="token punctuation">,</span> -50%<span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br></div></div><p>Flexbox解决方案</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.father</span><span class="token punctuation">{</span>
    <span class="token property">display</span><span class="token punctuation">:</span>flex<span class="token punctuation">;</span>
	<span class="token property">height</span><span class="token punctuation">:</span> 100px<span class="token punctuation">;</span> 
	<span class="token property">width</span><span class="token punctuation">:</span> 200px<span class="token punctuation">;</span>
	<span class="token property">background-color</span><span class="token punctuation">:</span> aquamarine<span class="token punctuation">;</span>
    <span class="token property">align-items</span><span class="token punctuation">:</span> center<span class="token punctuation">;</span>
    <span class="token property">justify-content</span><span class="token punctuation">:</span>center<span class="token punctuation">;</span>
   
<span class="token punctuation">}</span>
<span class="token selector">//匿名容器
.son</span><span class="token punctuation">{</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br></div></div><hr> <h2 id="盒模型"><a href="#盒模型" class="header-anchor">#</a> 盒模型</h2> <p>CSS3 中的盒模型有以下两种：<strong>标准盒模型</strong>、<strong>IE（替代）盒模型</strong>。</p> <p>两种盒子模型都是由 <code>content + padding + border + margin</code> 构成，其大小都是由 <code>content + padding + border</code> 决定的，但是盒子内容宽/高度（即 <code>width/height</code>）的计算范围根据盒模型的不同会有所不同：</p> <ul><li>标准盒模型：只包含 <code>content</code> 。</li> <li>IE（替代）盒模型：<code>content + padding + border</code> 。</li></ul> <p>可以通过 <code>box-sizing</code> 来改变元素的盒模型：</p> <ul><li><code>box-sizing: content-box</code> ：标准盒模型（默认值）。</li> <li><code>box-sizing: border-box</code> ：IE（替代）盒模型。</li></ul> <h2 id="响应式布局"><a href="#响应式布局" class="header-anchor">#</a> 响应式布局</h2> <ul><li>媒体查询+rem;</li> <li>vw/vh;（网页视口宽高的1/100），vmax取两者的最大值，vmin取两者的最小值；</li> <li>ua;</li></ul> <h2 id="选择器优先级"><a href="#选择器优先级" class="header-anchor">#</a> 选择器优先级</h2> <p>内联 &gt; ID选择器 &gt; 类选择器 &gt; 标签选择器</p> <h2 id="如何写一个宽高等比例的盒子"><a href="#如何写一个宽高等比例的盒子" class="header-anchor">#</a> 如何写一个宽高等比例的盒子</h2> <p>利用padding的百分比是相对于父元素宽度。</p> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.box</span><span class="token punctuation">{</span>
<span class="token property">width</span><span class="token punctuation">:</span>50%<span class="token punctuation">;</span>
<span class="token property">height</span><span class="token punctuation">:</span>0<span class="token punctuation">;</span>
<span class="token property">background</span><span class="token punctuation">:</span>purple<span class="token punctuation">;</span>
<span class="token comment">/*padding使用百分比的话，以横轴为比例*/</span>
<span class="token property">padding-bottom</span><span class="token punctuation">:</span>50%<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><hr> <h2 id="bfc"><a href="#bfc" class="header-anchor">#</a> BFC</h2> <p>什么是BFC：Block Formatting Context，解释为块级格式化上下文</p> <p><strong>一块独立的渲染区域，内部元素的渲染不会影响边界以外的元素。</strong></p> <p>一个HTML元素要创建BFC，则满足下列的任意一个或多个条件即可：</p> <p>1、float的值不是none。（float:left 或者float:right）</p> <p>2、position的值不是static或者relative。（position:absolute或者position:fixed）</p> <p>3、display的值是inline-block、flex等(都是指父级元素)</p> <p>4、overflow的值不是visible（overflow:hidden、overflow:scroll）</p> <p>5、父元素与正常文件流的子元素（非浮动子元素）自动形成一个BFC</p> <h2 id="offsetheight-scrollheight-clientheight有什么区别"><a href="#offsetheight-scrollheight-clientheight有什么区别" class="header-anchor">#</a> offsetHeight-scrollHeight-clientHeight有什么区别</h2> <p><img src="https://gitee.com/ekzodia_lty/blog-image/raw/master/img/20220306200442.png" alt=""></p> <p><img src="https://gitee.com/ekzodia_lty/blog-image/raw/master/img/20220306200743.png" alt=""></p> <h2 id="htmlcollention和nodelist的区别"><a href="#htmlcollention和nodelist的区别" class="header-anchor">#</a> HTMLCollention和NodeList的区别</h2> <ul><li>HTMLCollention 是 Element（HTML元素）的集合；</li> <li>NodeList是Node的集合；</li> <li>Node包含了Element、注释、内容等等；</li> <li>elem.childNodes和elem.children不一样，前者包含Text和Comment节点；</li></ul> <h2 id="圣杯布局和双飞翼布局"><a href="#圣杯布局和双飞翼布局" class="header-anchor">#</a> 圣杯布局和双飞翼布局</h2> <p><strong>目的</strong></p> <ul><li>三栏布局，中间一栏最先加载和渲染（内容最重要）；</li> <li>两侧内容固定，中间内容随着宽度自适应；</li> <li>一般用于PC网页；</li></ul> <p><strong>技术总结</strong></p> <ul><li>使用float布局；</li> <li>两侧使用margin负值，以便和中间内容横向重叠；</li> <li>防止中间内容被两侧覆盖，一个用padding一个用margin；</li></ul> <h2 id="clearfix清除浮动"><a href="#clearfix清除浮动" class="header-anchor">#</a> clearfix清除浮动</h2> <div class="language-css line-numbers-mode"><pre class="language-css"><code><span class="token selector">.clearfix:after</span><span class="token punctuation">{</span>
	<span class="token property">content</span><span class="token punctuation">:</span><span class="token string">''</span><span class="token punctuation">;</span>
	<span class="token property">display</span><span class="token punctuation">:</span>block<span class="token punctuation">;</span>
	<span class="token property">clear</span><span class="token punctuation">:</span>both<span class="token punctuation">;</span>
    <span class="token property">height</span><span class="token punctuation">:</span>0<span class="token punctuation">;</span>
    <span class="token property">visibility</span><span class="token punctuation">:</span>hidden<span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">3/20/2022, 10:07:00 PM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#h5新增特性" class="sidebar-link reco-side-h5新增特性" data-v-cb1513f6>H5新增特性</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#如何理解-html-语义化" class="sidebar-link reco-side-如何理解-html-语义化" data-v-cb1513f6>如何理解 HTML 语义化？</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#块级元素与行内元素" class="sidebar-link reco-side-块级元素与行内元素" data-v-cb1513f6>块级元素与行内元素</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#css3新增特性" class="sidebar-link reco-side-css3新增特性" data-v-cb1513f6>CSS3新增特性</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#margin负值问题" class="sidebar-link reco-side-margin负值问题" data-v-cb1513f6>margin负值问题</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#水平垂直居中方法" class="sidebar-link reco-side-水平垂直居中方法" data-v-cb1513f6>水平垂直居中方法</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#盒模型" class="sidebar-link reco-side-盒模型" data-v-cb1513f6>盒模型</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#响应式布局" class="sidebar-link reco-side-响应式布局" data-v-cb1513f6>响应式布局</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#选择器优先级" class="sidebar-link reco-side-选择器优先级" data-v-cb1513f6>选择器优先级</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#如何写一个宽高等比例的盒子" class="sidebar-link reco-side-如何写一个宽高等比例的盒子" data-v-cb1513f6>如何写一个宽高等比例的盒子</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#bfc" class="sidebar-link reco-side-bfc" data-v-cb1513f6>BFC</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#offsetheight-scrollheight-clientheight有什么区别" class="sidebar-link reco-side-offsetheight-scrollheight-clientheight有什么区别" data-v-cb1513f6>offsetHeight-scrollHeight-clientHeight有什么区别</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#htmlcollention和nodelist的区别" class="sidebar-link reco-side-htmlcollention和nodelist的区别" data-v-cb1513f6>HTMLCollention和NodeList的区别</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#圣杯布局和双飞翼布局" class="sidebar-link reco-side-圣杯布局和双飞翼布局" data-v-cb1513f6>圣杯布局和双飞翼布局</a></li><li class="level-2" data-v-cb1513f6><a href="/blog/blogs/Summary/7.htmlcss.html#clearfix清除浮动" class="sidebar-link reco-side-clearfix清除浮动" data-v-cb1513f6>clearfix清除浮动</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/blog/assets/js/app.2c497286.js" defer></script><script src="/blog/assets/js/3.1e41fb2d.js" defer></script><script src="/blog/assets/js/1.a1bf8e1e.js" defer></script><script src="/blog/assets/js/37.38b67684.js" defer></script>
  </body>
</html>
